package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.bean.DtsStorage;
import com.itqf.dto.DtsSearchDto;
import com.itqf.mapper.DtsStorageMapper;
import com.itqf.service.DtsStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: shop_manage
 *
 * @author: MaTianWei
 * time: 2021/7/16 20:27
 * description:
 */
@Service
public class DtsStorageServiceImpl implements DtsStorageService {
    //上传到阿里云
    @Autowired
    private DtsStorageMapper dtsStorageMapper;
    @Override
    public void save(DtsStorage dtsStorage) {
        dtsStorageMapper.insert(dtsStorage);
    }

    @Override
    public Map query(DtsSearchDto dto) {
        PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<DtsStorage>dtsStorages = dtsStorageMapper.queryList(dto);
        PageInfo<DtsStorage>pageInfo = new PageInfo<>(dtsStorages);

        Map data = new HashMap();
        data.put("total",pageInfo.getTotal());
        data.put("items",pageInfo.getList());
        return data;
    }
    //oss删除
    @Override
    public int delete(Integer id) {
        int rows =  dtsStorageMapper.deleteByPrimaryKey(id);
        return rows;
    }
    //oss更新
    @Override
    public int update(DtsStorage dtsStorage) {
        dtsStorage.setAddTime(new Date());
        int rows = dtsStorageMapper.updateByPrimaryKeySelective(dtsStorage);
        return rows;
    }
}
